package com.norman.sorry.core.cards;

import java.util.Collection;
import java.util.Map;

import com.norman.sorry.core.moves.IMove;
import com.norman.sorry.core.moves.MoveFactory;
import com.norman.sorry.core.pieces.IPiece;
import com.norman.sorry.core.players.IPlayer;
import com.norman.sorry.core.tiles.ILinkedTile;

/**
 * The class representation of the eleven card. This card allows the player to
 * move any game piece eleven tiles forward or switch any game piece that is on
 * the board with one of their own game pieces that is also on the board.
 * 
 * @author Brian Norman
 * @version 0.0.1 beta
 * @since 0.0.1 beta
 */
public class Eleven extends AbstractCard {

   /**
    * Definition of the constant integer eleven.
    */
   public static final int ELEVEN = 11;

   /**
    * {@inheritDoc}
    * 
    * Returns the moves of each game piece moving eleven tiles forward that can
    * and every possible switch of game pieces that is legal.
    * 
    * @see com.norman.sorry.core.cards.ICard#getMoves(IPlayer, Map)
    */
   @Override
   public Collection<IMove> getMoves(IPlayer player, Map<IPiece, ILinkedTile> pieces) {
      Collection<IMove> moves = getMoves(player, pieces, ELEVEN);

      for (IPiece pPiece : player.getPieces()) {
         ILinkedTile pTile = pieces.get(pPiece);
         if (pTile == null || pTile.isSafe()) {
            continue;
         }

         for (IPiece ePiece : pieces.keySet()) {
            if (ePiece.equals(pPiece) || ePiece.getColor().equals(pPiece.getColor())) {
               continue;
            }

            ILinkedTile eTile = pieces.get(pPiece);
            if (eTile == null || eTile.isSafe()) {
               continue;
            }

            IMove m = MoveFactory.createSwitchMove(pPiece, pTile, ePiece, eTile);
            if (m != null) {
               moves.add(m);
            }
         }
      }
      return moves;
   }

}
